<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="generator" content=
"HTML Tidy for Windows (vers 14 February 2006), see www.w3.org" />
<title>Reconditioned Machines</title>
<link rel="stylesheet" href="home.css" type="text/css" />
</head>
<body>

<div class="page">
<?php include 'menu.php'; verifySession(); connectDB(); ?>
<center>

<table>
<tr>
<td class="pageTitle">RECONDITIONED MACHINES - ADMINISTRATION</td>
</tr>
</table>

<div style="width:780px">

<div style="text-align:left;padding-left:100px">
<h3>Directions:</h3>
<ul>
<li><img src="images/b_edit.png" /> - This icon means "EDIT" and you can use it to edit the machine's information.</li>
<li><img src="images/b_drop.png" /> - This icon means "DELETE" and will remove the machine from the list.</li>
</ul>
</div>

<div style="border:1px solid black">
<h3>ADD A NEW MACHINE:</h3>
<p>(type '&amp;Oslash' for a '&Oslash' symbol)</p>

<?php
	$cats = mysql_query("SELECT * FROM category_xref");
	if (!$cats) {
	echo("<P>Error performing query: " . mysql_error() . "</P>");
	exit();
	}
?>

<form method="POST" enctype="multipart/form-data" name="image_upload_form" action="reconditioned_add.php">
<p>Category:</p>
<select id='category' name='category'>
<option value=''></option>

<?php
	while ( $catRow = mysql_fetch_array($cats) ) {
	  echo("<option value='" . $catRow["catCode"] . "'>" . $catRow["Description"] . "</option>");
	}
	echo("</select>");
?>
<table class="reconditioned" width="768px">
<tr>
<td class="majHeading" width="10%">UNIT #</td>
<td class="majHeading" width="55%">UNIT INFORMATION</td>
<td class="majHeading" width="10%">PRICE</td>
<td class="majHeading" width="25%">
<center><img src="images/photo.gif" alt="photo" /><b>**2MB MAX!!**</b></center>
</td>
</tr>

<script language="javascript" type="text/javascript">
  function validate(){
	if (document.getElementById('category').value == '')
	{
		alert('Please choose a category.');
		return false;
	}
	if (document.getElementById('cowtag').value == '')
	{
		alert('Please fill unit number.');
		return false;
	}
	if (document.getElementById('description').value == '')
	{
		alert('Please fill description.');
		return false;
	}
	if (document.getElementById('price').value == '')
	{
		alert('Please fill price.');
		return false;
	}
	if (isNaN(document.getElementById('price').value))
	{
		alert('Price should only be numbers.');
		return false;
	}
	
	return true;
  }
</script>

<tr>
<td><input id='cowtag' size='5' name='cowtag' type='text' /></td>
<td><input id='description' size='60' name='description' type='text' /></td>
<td>$<input id='price' size='5' name='price' type='text' /></td>
<td><center></center><input type="file" name="image_file" size="10" /></td>
</tr>

</table>
<p id="errormsg"></p>

<p>
<input id="submitButton" type="submit" value="Add machine" name="action" onclick="javascript:return validate()" />
</p></form>
</div>

<h3>EDIT EXISTING MACHINES:</h3>
<table class="reconditioned" width="770px">
<tr>
<td><img src="images/b_edit.png" height='16' /></td>
<td><img src="images/b_drop.png" height='16' /></td>
<td class="majHeading" width="10%">UNIT #</td>
<td class="majHeading" width="75%">UNIT INFORMATION</td>
<td class="majHeading" width="10%">PRICE</td>
<td class="majHeading" width="5%">
<center><img src="images/photo.gif" alt="" /></center>
</td>
</tr>

<?php
  
  // Request the categories
  $cats = mysql_query(
            "SELECT * FROM category_xref");
  if (!$cats) {
    echo("<P>Error performing query: " .
         mysql_error() . "</P>");
    exit();
  }

  // Display the column headings
  while ( $catRow = mysql_fetch_array($cats) ) {

    echo("<tr><td colspan='6' class='minHeading'>" . $catRow["Description"] . "</td></tr>"); 

    // Request the machines for this category
    $machines = mysql_query(
	  	"SELECT * FROM reconditioned WHERE category = " . $catRow["catCode"] . " ORDER BY price ASC");
    if (!$machines) {
      echo("<P>Error performing query: " .
           mysql_error() . "</P>");
      exit();
    }
    // Display each machine in this category

    $machineCount = 0;
    while ( $machineRow = mysql_fetch_array($machines) ) {
	$machineCount++;
	echo("<tr><td><a href=\"reconditioned_edit.php?machineID=" . $machineRow["machineID"] . "\"><img src=\"images/b_edit.png\" height='16' /></a></td>");
	echo("<td><a href=\"reconditioned_delete.php?machineID=" . $machineRow["machineID"] . "\"><img src=\"images/b_drop.png\" height='16' /></a></td>");
	echo("<td class='caps'>" . $machineRow["cowtag"] . "</td>");
	echo("<td class='caps'>" . $machineRow["description"] . "</td>");
	echo("<td width='20%'>$" . $machineRow["price"] . "</td>");
	if (!empty($machineRow["piclink"]) && !empty($machineRow["piclink"])) {
	  echo("<td align='center'><a href=\"javascript:PopupPic('" . $machineRow["piclink"] . "')\">");
	  echo("<img src=\"" . $machineRow["thumblink"] . "\" height='60' /></a></td></tr>");
	}
	else
	  echo("<td align='center'><img src='pictures/reconditioned/nopicthumb.jpg' height='60' /></td></tr>");


    }
    if ($machineCount == 0) 
        echo("<tr><td colspan='6' class='caps'>none available at this time</td></tr>");
  }

?>

</table>

</div>
</div>
</body>
</html>
